package cc.springsecurity.auth2.server.model;

/**
 * 响应结果实体
 * 
 * @author CC
 *
 */
public class ResponseResult implements java.io.Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 8042452306181479037L;
	private static final String RESULT_SUCCESS_MGS = "操作已成功";
	private static final String RESULT_FAIL_EXCPETION_MGS = "操作失败，出现未知错误，请稍后重试或请联系管理员";
	private static final String RESULT_FAIL_MGS = "操作失败，请稍后重试";

	private String msg;
	private boolean success;
	private Object obj;

	private ResponseResult(boolean success, String msg, Object obj) {
		super();
		this.msg = msg;
		this.success = success;
		this.obj = obj;
	}

	public String getMsg() {
		return msg;
	}

	public boolean isSuccess() {
		return success;
	}

	public Object getObj() {
		return obj;
	}

	public static ResponseResult success() {
		ResponseResult result = new ResponseResult(true, RESULT_SUCCESS_MGS, null);
		return result;
	}

	public static ResponseResult success(Object obj) {
		ResponseResult result = new ResponseResult(true, RESULT_SUCCESS_MGS, obj);
		return result;
	}

	public static ResponseResult success(String msg, Object obj) {
		ResponseResult result = new ResponseResult(true, msg, obj);
		return result;
	}

	public static ResponseResult returnResult(Boolean isSuccess, String msg, Object obj) {
		ResponseResult result = new ResponseResult(isSuccess, msg, obj);
		return result;
	}

	public static ResponseResult returnResult(int count) {
		if (count > 0) {
			ResponseResult result = new ResponseResult(true, RESULT_SUCCESS_MGS, null);
			return result;
		} else {
			ResponseResult result = new ResponseResult(false, RESULT_FAIL_MGS, null);
			return result;
		}
	}

	public static ResponseResult fail(Exception exception) {
		ResponseResult result = new ResponseResult(false, RESULT_FAIL_EXCPETION_MGS, exception);
		return result;
	}

	public static ResponseResult fail(String msg, Object obj) {
		ResponseResult result = new ResponseResult(false, msg, obj);
		return result;
	}
}
